﻿using B.S.Traceability.Domain;
using B.S.Traceability.Error;
using B.S.Traceability.Infrastructure.Interface;
using B.S.Traceability.Read.API.Application.Commends.Company;
using MediatR;

namespace B.S.Traceability.Read.API.Application.CommendHandlers.Company
{
    public class GetCompanyCommendHandlers : IRequestHandler<GetCompanyCommends, APIResult<List<Companys>>>
    {

        private readonly IBaseRepository<Companys> companysRepository;

        public GetCompanyCommendHandlers(IBaseRepository<Companys> companysRepository)
        {
            this.companysRepository = companysRepository;
        }

        /// <summary>
        /// 显示企业信息
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public async Task<APIResult<List<Companys>>> Handle(GetCompanyCommends request, CancellationToken cancellationToken)
        {
            APIResult<List<Companys>> result = new APIResult<List<Companys>>();
            result.Code = APIEnum.查询成功;
            result.Msg = "查询成功";
            var list = companysRepository.GetAll().Where(p => p.BatchId == request.BatchId);
            result.data = list.ToList();
            return await Task.FromResult(result);
        }
    }
}
